$(function(){
	chrome.storage.sync.get(["interval", "follow", "reply", "who", "what"], result => {
        console.info('YKT->', result)
        const $intervalValue = $("#intervalValue");
        if(result["interval"]){
			$intervalValue.val(parseInt(result["interval"]) / 1000);
		}
		if(result["follow"] === "true"){
			$("#follow").prop("checked", true)
		}
        const $whoValue = $("#whoValue");
        if(result["who"]){
			$whoValue.val(result["who"])
		}
        const $whatValue = $("#whatValue");
		if(result["what"]){
			$whatValue.val(result["what"])
		}
		if(result["reply"] === "true"){
            $("#reply").prop("checked", true)
		}
        $("#save").bind("click", () => {
            let form = $("#form").serialize();
            let f = {
                interval: '',
                follow: '',
                reply: '',
                who: '',
                what: ''
            }
            let arr = form.split("&");
            let followArr = arr[0].split("=");
            let replyArr = arr[1].split("=");
            f.follow = followArr[1] + ''
            f.reply = replyArr[1] + ''
            if ($intervalValue.val().trim()){
                f.interval = parseInt($intervalValue.val().trim()) * 1000
            }
            if ($whoValue.val().trim()){
                f.who = $whoValue.val().trim()
            }
            if ($whatValue.val().trim()){
                f.what = $whatValue.val().trim()
            }
            chrome.storage.sync.set(f, () => {
                console.info("YKT->保存成功：", f)
            })
        })
        $("#join").bind("click", ()=>{
            window.open('https://www.yuketang.cn/v2/web/index')
        })
	});
});